In [98]:
import serial
import re
import math
import sys
In [2]:
LF = "\x0A"
CR = "\x0D"
FF = "\x0C"
ESC = "\x1B"
CAN = "\x18"
SP = "\x20"
GS = "\x1D"
NULL = chr(0)
In [82]:
connection = serial.Serial(port="/dev/ttyUSB0",baudrate=19200)
In [83]:
w = connection.write
def cut():
w(LF+LF+LF+LF+ESC+'i'+LF)
In [84]:
connection.write('\x0A')
Out[84]:
In [125]:
cut()
cf page 50
[Function] Defining the download bit image
[Code]
[Range]
[Outline]
[Caution]
[See Also]
[Sample Program]
GOSUB IMG
LPRINT CHR$(&H1D);"/"; CHR$(0);
LPRINT CHR$(&H1D);"/"; CHR$(1);
LPRINT CHR$(&H1D);"/"; CHR$(2);
LPRINT CHR$(&H1D);"/"; CHR$(3);
END
IMG:
n1=10:n2=5
LPRINT CHR$(&H1D);"*";
LPRINT CHR$(n1); CHR$(n2);
FOR J=1 TO n1*8
FOR I=1 TO n2
LPRINT CHR$(J);
NEXT I
NEXT J
RETURN
In [34]:
n1=1
n2=1
w(GS+'*')
w(chr(n1))
w(chr(n2))
for k in range(4*n1):
for l in range(n2):
w("\xFA")
w("\xF0")
In [39]:
w("n1=%s, n2=%s"%(n1,n2) + LF)
for k in range(0,4):
w("%s"%k+LF)
w(GS+"/"+chr(k)+LF)
cut()
Out[39]:
[Code] <1D>H<76>H<30>H<m><xL><xH><yL><yH> [<d>] k
[Range]
[Outline] Prints raster bit images in mode “m”.
In [86]:
def startRaster(mode,xL,xH,yL,yH):
w(GS+'v0') #Printing of raster bit imag
w(chr(mode)) #Print mode (0:normal, 1:double width, 2:double height, 3: quadruple size)
w(chr(xL)) #xL
w(chr(xH)) #xH
w(chr(yL)) #yL
w(chr(yH)) #yH
In [95]:
startRaster(3,2,0,5,0)
# 2 lignes noires
w('\xFF')
w('\xFF')
# 2lignes mi noires, mi blanches
w('\x0F')
w('\x0F')
# 2 lignes mi blanches, mi noires
w('\xF0')
w('\xF0')
# grille d'1px sur deux en decalé sur 4 lignes
w('\xAA')
w('\x55')
w('\xAA')
w('\x55')
cut()
In [93]:
startRaster(3,1,0,2,0)
w('\xAA')
w('\xAA')
cut()
In [123]:
def printPBM(filename,mode=3):
with open(filename,'r') as f:
while True:
header = f.readline().strip()
if header.startswith('#'):
continue
elif header == 'P1':
assert False, 'ASCII format not supported'
elif header == 'P4':
break
else:
assert False, 'Bad format !'
rows, cols = 0, 0
while True:
header = f.readline().strip()
if header.startswith('#'):
continue
else:
match = re.match('^(\d+) (\d+)$',header)
if match is None:
assert False, 'Bad size'
else:
cols, rows = match.groups()
break
rows, cols = int(rows), int(cols)
assert (rows, cols) != (0, 0)
colbytes = int(math.ceil(cols/8.0))
xL,xH = colbytes%256, int(math.floor(colbytes/256.0))
yL,yH = rows%256, int(math.floor(rows/256.0))
startRaster(mode,xL,xH,yL,yH)
for n in range(0,rows):
for m in range(0,colbytes):
mychar = f.read(1)
#sys.stdout.write('%02X' % ord(mychar))
w(mychar)
In [126]:
w("Bienvenue au Carrefour Numerique")
w(LF)
printPBM('/opt/pbm/cerveau.pbm',0)
cut()